home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV1-4.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  645b  |  40 lines

  1. #define HEADER "C++ Problem 1.4 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4.  
  5. class counter {
  6.   int count;
  7. public:
  8.   void set(int);
  9.   void increment(void);
  10.   void display(void);
  11. };
  12.  
  13. void counter::set (int new_value) {
  14.   count = new_value;
  15. }
  16.  
  17. void counter::increment (void) {
  18.   count++;
  19. }
  20.  
  21. void counter::display (void) {
  22.   printf("The count of the object at address %p is %d\n",
  23.          this, count);
  24. }
  25.  
  26. void main(void)
  27. {
  28.   printf("%s\n", HEADER);
  29.  
  30.   counter c1, c2;
  31.   c1.set (5);
  32.   c2.set (-12);
  33.   c1.display();
  34.   c2.display();
  35.   c1.increment();
  36.   c2.increment();
  37.   c1.display();
  38.   c2.display();
  39. }
  40.